package demo6;

import java.util.Arrays;

public class Test {
    public static void main(String[] args) {
        Student student1 = new Student("zhangSan",18);
        Student student2 = new Student("liSi",17);
        NameComparator nameComparator = new NameComparator();
        int ret = nameComparator.compare(student1,student2);
        if(ret > 0) {
            System.out.println("student1 > student2");
        }else if(ret == 0) {
            System.out.println("student1 == student2");
        }else {
            System.out.println("student1 < student2");
        }
    }
    public static void main1(String[] args) {
        Student student1 = new Student("zhangSan",18);
        Student student2 = new Student("liSi",17);
        Student student3 = new Student("aBao",13);
        Student[] students = new Student[3];
        students[0] = student1;
        students[1] = student2;
        students[2] = student3;
//        Arrays.sort(students);
//        System.out.println(Arrays.toString(students));
        bubbleSort(students);
        System.out.println(Arrays.toString(students));
//        int ret = student1.compareTo(student2);
//        if(ret > 0) {
//            System.out.println("student1 > student2");
//        }else if(ret == 0) {
//            System.out.println("student1 == student2");
//        }else {
//            System.out.println("student1 < student2");
//        }
    }
    public static void bubbleSort(Student[] students) {
        for (int i = 0; i < students.length-1; i++) {
            for (int j = 0; j < students.length-1-i; j++) {
                if(students[j].compareTo(students[j+1]) > 0) {
                    Student tmp = students[j];
                    students[j] = students[j+1];
                    students[j+1] = tmp;
                }
            }
        }
    }
}
